﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using YasharEl.Infrastructure.ProcessEngine.ServiceModel;
using YasharEl.Infrastructure.ServiceModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YasharEl.Infrastructure.Core.ServiceModel;

namespace YasharEl.Infrastructure.AllModules.AcceptanceTests.ProcessEngine.Steps
{
    [Binding]
    public class RetrieveProcessDefinitionInformationStepDefinition
    {
        #region Fields

        private RetrieveProcessDefinitionRequest _retrieveProcessDefinitionRequest;
        private RetrieveProcessDefinitionResponse _retrieveProcessDefinitionResponse;
        private PropertyDefinitionDTO _testLongProperty;
        private PropertyDefinitionDTO _testStringProperty;
        private PropertyDefinitionDTO _testIntegerProperty;
        private PropertyDefinitionDTO _testAddressProperty;
        private PropertyDefinitionDTO _testBooleanProperty;
        private PropertyDefinitionDTO _testDecimalProperty;
        private PropertyDefinitionDTO _testDoubleProperty;
        private PropertyDefinitionDTO _testDateTimeProperty;

        #endregion

        #region Given

        [Given(@"I have filled out the process definition id : (.*)")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void GivenIHaveFilledOutTheProcessDefinitionId(long processDefinitionId)
        {
            _retrieveProcessDefinitionRequest = new RetrieveProcessDefinitionRequest()
            {
                ProcessDefinitionId = processDefinitionId
            };
        }

        [Given(@"I have filled out the application id : (.*)")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void GivenIHaveFilledOutTheApplicationId(long applicationId)
        {
            _retrieveProcessDefinitionRequest.ApplicationId = applicationId;
        }

        #endregion

        #region When

        [When(@"I retrieve process metadata from process definitions catalog")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void WhenIRetrieveProcessMetadataFromProcessDefinitionsCatalog()
        {
            using (ServiceProxy<IProcessMetadataRetriever> processMetadataRetrieverProxy = new ServiceProxy<IProcessMetadataRetriever>())
            {
                _retrieveProcessDefinitionResponse = processMetadataRetrieverProxy.Proxy.RetrieveProcessDefinition(_retrieveProcessDefinitionRequest);
            }
        }

        #endregion

        #region Then

        [Then(@"I should receive valid process metadata response")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenIShouldReceiveValidProcessMetadataResponse()
        {
            Assert.IsNotNull(_retrieveProcessDefinitionResponse);
            Assert.IsNotNull(_retrieveProcessDefinitionResponse.ProcessDefinition);
        }

        [Then(@"the returned process metadata information contains the process definition name : (.*)")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationContainsTheProcessDefinitionName(string processDefinitionName)
        {
            Assert.AreEqual<string>(processDefinitionName, _retrieveProcessDefinitionResponse.ProcessDefinition.ProcessDefinitionName);
        }

        [Then(@"the returned process metadata information contains the process definition description : (.*)")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationContainsTheProcessDefinitionDescription(string processDefinitionDescription)
        {
            Assert.AreEqual<string>(processDefinitionDescription, _retrieveProcessDefinitionResponse.ProcessDefinition.ProcessDefinitionDescription);
        }

        [Then(@"the returned process metadata information has defined properties")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasDefinedProperties()
        {
            Assert.IsNotNull(_retrieveProcessDefinitionResponse.DefinedProperties);
            Assert.IsTrue(_retrieveProcessDefinitionResponse.DefinedProperties.Count > 0);
        }

        [Then(@"the returned process metadata information has 'TestLongProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestLongPropertyProperty()
        {
            _testLongProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestLongProperty");
            Assert.IsNotNull(_testLongProperty);
        }

        [Then(@"the 'TestLongProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestLongPropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testLongProperty.PropertyName);
        }

        [Then(@"the returned process metadata information has 'TestStringProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestStringPropertyProperty()
        {
            _testStringProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestStringProperty");
            Assert.IsNotNull(_testStringProperty);
        }

        [Then(@"the 'TestStringProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestStringPropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testStringProperty.PropertyName);
        }

        [Then(@"the returned process metadata information has 'TestIntegerProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestIntegerPropertyProperty()
        {
            _testIntegerProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestIntegerProperty");
            Assert.IsNotNull(_testIntegerProperty);
        }

        [Then(@"the 'TestIntegerProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestIntegerPropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testIntegerProperty.PropertyName);
        }

        [Then(@"the returned process metadata information has 'TestAddressProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestAddressPropertyProperty()
        {
            _testAddressProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestAddressProperty");
            Assert.IsNotNull(_testAddressProperty);
        }

        [Then(@"the 'TestAddressProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestAddressPropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testAddressProperty.PropertyName);
        }

        [Then(@"the returned process metadata information has 'TestBooleanProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestBooleanPropertyProperty()
        {
            _testBooleanProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestBooleanProperty");
            Assert.IsNotNull(_testBooleanProperty);
        }

        [Then(@"the 'TestBooleanProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestBooleanPropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testBooleanProperty.PropertyName);
        }

        [Then(@"the returned process metadata information has 'TestDecimalProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestDecimalPropertyProperty()
        {
            _testDecimalProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestDecimalProperty");
            Assert.IsNotNull(_testDecimalProperty);
        }

        [Then(@"the 'TestDecimalProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestDecimalPropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testDecimalProperty.PropertyName);
        }

        [Then(@"the returned process metadata information has 'TestDoubleProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestDoublePropertyProperty()
        {
            _testDoubleProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestDoubleProperty");
            Assert.IsNotNull(_testDoubleProperty);
        }

        [Then(@"the 'TestDoubleProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestDoublePropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testDoubleProperty.PropertyName);
        }

        [Then(@"the returned process metadata information has 'TestDateTimeProperty' property")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheReturnedProcessMetadataInformationHasTestDateTimePropertyProperty()
        {
            _testDateTimeProperty = _retrieveProcessDefinitionResponse.DefinedProperties.Find((d) => d.PropertyKey == "TestDateTimeProperty");
            Assert.IsNotNull(_testDateTimeProperty);
        }

        [Then(@"the 'TestDateTimeProperty' property contains the property name : '(.*)'")]
        [Scope(Tag = "RetrieveProcessDefinitionInformation")]
        public void ThenTheTestDateTimePropertyPropertyContainsThePropertyName(string name)
        {
            Assert.AreEqual<string>(name, _testDateTimeProperty.PropertyName);
        }

        #endregion
    }
}
